<?php
namespace app\index\model;
use think\Db;
use think\Model;
class Process extends  Model
{
    //删除确认过的标本信息  先判断是否接入样本列表里面
    public  function  ConfirmYbDel($ybid){
                $res1 = Db::table('Ls_Camera')->where('Code',$ybid)->delete();
                $res2 = Db::table('Ls_Camera')->where('Code',$ybid)->delete();
                "DELETE FROM dbo.Ls_CameraFile WHERE ServerId IN 
                 (SELECT ServerId FROM dbo.Ls_CameraFileRelation WHERE code between '611070001306' and '611070001307' )
                DELETE FROM dbo.Ls_CameraFileRelation WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.Ls_MSpecInputFirst WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.Ls_MSpecInputFirstApplyItem WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.Ls_MSpecInputSecond WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.Ls_MSpecInputSecondApplyItem WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.f_k_ybxx WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM dbo.f_k_jymd WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM dbo.f_k_ybxx_picture WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM dbo.t_lis_sampletransPro WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM dbo.t_lis_samplereg WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM  dbo.S_SampleDetail WHERE s_barcode between '611070001306' and '611070001307' 
                DELETE FROM  dbo.t_lis_tasks WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM  t_lis_sampletransPro WHERE ybid between '611070001306' and '611070001307' ";
    }

    //按照批量批量范围删确认标本
    public  function ConfirmYbDelAll($beginid,$endid){
        $res1 = Db::table('Ls_Camera')->where('Code',$ybid)->delete();
        $res2 = Db::table('Ls_Camera')->where('Code',$ybid)->delete();
        "DELETE FROM dbo.Ls_CameraFile WHERE ServerId IN 
                 (SELECT ServerId FROM dbo.Ls_CameraFileRelation WHERE code between '611070001306' and '611070001307' )
                DELETE FROM dbo.Ls_CameraFileRelation WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.Ls_MSpecInputFirst WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.Ls_MSpecInputFirstApplyItem WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.Ls_MSpecInputSecond WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.Ls_MSpecInputSecondApplyItem WHERE code between '611070001306' and '611070001307' 
                DELETE FROM dbo.f_k_ybxx WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM dbo.f_k_jymd WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM dbo.f_k_ybxx_picture WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM dbo.t_lis_sampletransPro WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM dbo.t_lis_samplereg WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM  dbo.S_SampleDetail WHERE s_barcode between '611070001306' and '611070001307' 
                DELETE FROM  dbo.t_lis_tasks WHERE ybid between '611070001306' and '611070001307' 
                DELETE FROM  t_lis_sampletransPro WHERE ybid between '611070001306' and '611070001307' ";
    }



    //交接列表删除
    public function ConnectDel($ybid){
        //判断是否接入平台
        if(Model('report')->GetReportInfoByYbid($ybid)){
            return false;
        }
        //要判断是哪个专业组 才能删

        //查找交接列表是否有数据  -- 有两天记录就不能删了  条码重复 或者多个项目平台
        $res =$this->table('S_SampleDetail')->where('S_Barcode',$ybid)->find();
        if (!$res || count($res) > 1){
            return false;
        }
        //有数据 判断是否有S_SampleItem
        $this->table('S_SampleItem')->where('S_SampleId',$res['id'])->delete();
        //删除S_SampleDetail
        $this->table('S_SampleDetail')->where('S_Barcode',$ybid)->delete();

        //删除t_lis_tasks
        $this->table('t_lis_tasks')->where('ybid',$ybid)->delete();

        //删除t_lis_samplereg
        $this->table('t_lis_samplereg')->where('ybid',$ybid)->delete();

        //删除t_lis_sampletransPro

        $this->table('t_lis_sampletransPro')->where('ybid',$ybid)->delete();

        return true;

    }

}